package cn.ctbu.edu.redo1.service;

import cn.ctbu.edu.redo1.dao.StudentRepository;
import cn.ctbu.edu.redo1.entity.Student;
import org.hibernate.annotations.NaturalId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StudentService {
    @Autowired
    public StudentRepository studentRepository;
    public List<Student> getAll() {
        return studentRepository.findAll();
    }
    public Student findById(Integer id) {
        return studentRepository.findById(id).orElse(null);
    }
    public List<Student> findByNamelike(String name) {
        return studentRepository.findByNameLike(name);
    }
    public List<Student> findByNameAndSno(String name, String sno) {
        return studentRepository.findByNameAndSno(name,sno);
    }
    public void insert(Student student){
        studentRepository.save(student);
    }
    public Student update(Student student){
        return studentRepository.save(student);
    }
    public void delete(Integer id){
        studentRepository.deleteById(id);
    }
    public Student add(Student student){
        return studentRepository.save(student);
    }

}
